/**
 * \file containment.hpp
 * 
 * \section COPYRIGHT
 *
 * Basis: A 3D Mathematics Library
 *
 * ---------------------------------------------------------------------
 *
 * Copyright (c) 2010, Don Olmstead
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *  3. Neither the name of organization nor the names of its contributors may be
 *     used to endorse or promote products derived from this software without
 *     specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef BASIS_INTERPOLATION_HPP_INCLUDED
#define BASIS_INTERPOLATION_HPP_INCLUDED

#include <basis/clamping.hpp>

namespace basis
{

	//------------------------------------------------------------
	// Real number interpolation
	//------------------------------------------------------------

	/**
	 * Linearly interpolates between two values.
	 *
	 * Used to interpolate between real numbers.
	 *
	 * \tparam Real A real number type.
	 *
	 * \param value0 The first of two numbers to interpolate.
	 * \param value1 The second of two numbers to interpolate.
	 * \param amount A value between 0 and 1 indicating the weight of value1.
	 * \returns The interpolated value.
	 */
	template <typename Real>
	inline Real lerp(Real value0, Real value1, Real amount)
	{
		return value0 + (value1 - value0) * amount;
	}

	/**
	 * Interpolates between two values using a cubic equation.
	 *
	 * \tparam Real A real number type.
	 *
	 * \param value1 The first of two numbers to interpolate.
	 * \param value2 The second of two numbers to interpolate.
	 * \param amount The weighting value.
	 * \returns The interpolated value.
	 */
	template <typename Real>
	inline Real smoothstep(Real value1, Real value2, Real amount)
	{
		Real t = saturate((amount - value1) / (value2 - value1));

		return t * t * ((Real)3 - (Real)2 * t);
	}

	//------------------------------------------------------------
	// N-Tuple interpolation
	//------------------------------------------------------------

	/**
	 * Linearly interpolates between two values.
	 *
	 * Used to interpolate between n-tuples.
	 *
	 * \tparam NTuple An n-tuple type.
	 * \tparam Real A real number type.
	 *
	 * \param value0 The first of two numbers to interpolate.
	 * \param value1 The second of two numbers to interpolate.
	 * \param amount A value between 0 and 1 indicating the weight of value1.
	 * \returns The interpolated value.
	 */
	template <typename NTuple, typename Real>
	inline NTuple lerp(const NTuple& value0, const NTuple& value1, Real amount)
	{
		return value0 + (value1 - value0) * amount;
	}

} // end namespace basis

#endif // end BASIS_INTERPOLATION_HPP_INCLUDED
